﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ScrumTable.BL.DM.DataManagement;
using ScrumTable.DL.Data;
using ScrumTable.DL.Data.Common;
using ScrumTable.DL.Data.Local;

#endregion

namespace ScrumTable.BL.DM.Test
{
    /// <summary>
    /// This is the test class for DomainContextFactory class.
    /// </summary>
    [TestClass]
    public class DomainContextFactoryTest
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private IDataContext _context;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Use TestInitialize to run code before running each test .
        /// </summary>
        [TestInitialize]
        public void TestInitialize()
        {
            _context = DataConnectionFactory.Create(DataAssembly.FromAssembly(typeof(DataContext).Assembly));
        }

        /// <summary>
        /// Use TestCleanup to run code after each test has run.
        /// </summary>
        [TestCleanup]
        public void TestCleanup()
        {
            _context.Dispose();
            _context = null;
        }

        [TestMethod]
        public void TestCreate()
        {
            Assert.IsNotNull(DomainContextFactory.Create(_context));
        }

        [TestMethod]
        public void TestCreateNullFailed()
        {
            bool exceptionThrown = false;
            try
            {
                DomainContextFactory.Create(null);
            }
            catch (ArgumentNullException)
            {
                exceptionThrown = true;
            }

            if (!exceptionThrown)
            {
                Assert.Fail("Null pointers cannot be passed to the DomainContextFactory.Create() method.");
            }
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}
